package com.app.allwe.gui.panle;

import com.app.allwe.gui.SystemUtils;
import com.app.allwe.gui.countdown.TimeLabel;
import com.app.allwe.gui.text.TextLabel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.awt.*;

@Component
public class BasePanel extends JPanel {

    @Value("${pic.backGround.path}")
    private String picBackGroundPath;

    public BasePanel() {
        this.setLayout(new GridLayout(2, 1));
        // 设置提示语
        this.add(TextLabel.createTextLabel("休息一会吧"));
        // 设置倒计时
        this.add(TimeLabel.getTimeLabel());
    }

    public void paintComponent(Graphics graphics) {
        Graphics2D graphics_2 = (Graphics2D) graphics;

        // 设置背景图
        Image backGroundImage = new ImageIcon(picBackGroundPath).getImage();
        // 此处是重点，通过this获取窗体大小来设置图片大小
        ImageIcon backGroundImageIcon = new ImageIcon(backGroundImage);
        backGroundImageIcon.setImage(backGroundImage.getScaledInstance(SystemUtils.getSystemWidth(), SystemUtils.getSystemHeight(), Image.SCALE_AREA_AVERAGING));

        graphics_2.drawImage(backGroundImageIcon.getImage(), 0, 0, null);
    }


}
